package com.scy.controller;

import com.scy.entity.Book;
import com.scy.mapper.BookMapper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * 本类用来演示
 *
 * @author wwh
 * @date 2024/7/3 9:20 $
 */
@Controller
public class HelloController {

    @Resource
    BookMapper bookMapper;
    @GetMapping("/index")
    public String getPage(Model model){

        Book book = new Book();
        book.setBookName("三体");
        book.setBookPrice(1.99);

        model.addAttribute("msg","hello 苏城院!!!");
        model.addAttribute("html","<div>二hi黑恶</div>");
        model.addAttribute("book",book);
        return "index";
    }

    @GetMapping("/init")
    public String getAll(Model model){

        List<Book> books = bookMapper.selectList(null);

        model.addAttribute("books",books);

//        redirect:/index
        return "book/book-list";
    }
}
